package cn.eclass.servlet.front;

import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletException;

import cn.eclass.servlet.ActionFace;
import cn.eclass.utils.ConstantsConf;
import cn.eclass.utils.GiftOrderObject;
import cn.eclass.utils.UserSessionInfo;

public class Ugifts extends ActionFace {

	private void checkLogIn() throws ServletException, IOException {
		if(user != null) return;

		request.setAttribute("redirect", "ugifts");
		request.getRequestDispatcher(logInView).forward(request, response);
	}
	
	
	@Override
	public void doIndex() {
        try {
        	checkLogIn();
        	UserSessionInfo usi = new UserSessionInfo(user, session);
        	//The following functions save objects to session.
        	usi.setGiftOrderList();
    		String name = ConstantsConf.GIFTORDERLIST;
    		List<GiftOrderObject> list = (List<GiftOrderObject>) session.getAttribute(name);
    		int size = list.size();
        	//
    		request.setAttribute("giftListLength", size);
            request.getRequestDispatcher(view).forward(request, response);
        } catch (ServletException ex) {
            Logger.getLogger(Uhistory.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Uhistory.class.getName()).log(Level.SEVERE, null, ex);
        }
	}

}
